package com.app.micaihu.view.user.userinfo.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.infor.AvatarBean;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;

import java.util.List;

/**
 * Created by linkai on 2017/4/12.
 */
public class AvatarAdapter extends AppBaseAdapter<AvatarBean> {
    public AvatarAdapter(List<AvatarBean> list, Context context) {
        super(list, context);
    }


    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            convertView= inflater.inflate(R.layout.item_avater_layout,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder)convertView.getTag();
        }
        AvatarBean avatarBean=list.get(position);
        if (avatarBean!=null){
            if (avatarBean.url !=null&&!TextUtils.isEmpty(avatarBean.url))

                LoadImageUtils.getInstance().loadImage(viewHolder.icon_im,avatarBean.url);



            if (avatarBean.name!=null&&!TextUtils.isEmpty(avatarBean.name)){
                viewHolder.name_tv.setText(avatarBean.name);
            } else{
                viewHolder.name_tv.setText("");
            }

            if (avatarBean.selected){
                viewHolder.select_im.setVisibility(View.VISIBLE);
            }else{
                viewHolder.select_im.setVisibility(View.GONE);
            }
        }
        return convertView;
    }

    class ViewHolder{
        public CustomImageView icon_im;
        public TextView name_tv;
        private ImageView select_im;
        ViewHolder(View view){
            icon_im=(CustomImageView)view.findViewById(R.id.mieravatar_item_icon);
            ViewSizeUtils.changeViewAuto1080(icon_im, 200, 200);
            name_tv=(TextView)view.findViewById(R.id.mieravatar_item_name);
            select_im=(ImageView)view.findViewById(R.id.mieravatar_item_select);
        }
    }
}
